﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WEBDT.Base;
using WEBDT.ViewModel;

namespace WEBDT.Areas.Admin.Controllers
{
    public class NhaSXController : BaseController<NhaSX>
    {
        //
        // GET: /Admin/NhaSX/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public override ActionResult insert()
        {
            var model = new NhaSXModel
            {
                tontai = false,
            };
            return View(model);
        }

        [HttpPost]
        public override ActionResult insert(FormCollection fr)
        {
            var ht = new NhaSXModel
            {
                TenNSX = fr.Get("tennsx"),
                Diachi = fr.Get("diachi"),
                Email = fr.Get("email"),
                DienThoai = fr.Get("dienthoai"),
                fax = fr.Get("fax"),
            };
            var model = new NhaSX
            {
                TenNSX = ht.TenNSX,
                DiaChi = ht.Diachi,
                Email = ht.Email,
                DienThoai = ht.DienThoai,
                Fax = ht.fax,
            };
            repository.Insert<NhaSX>(model);
            return RedirectToAction("getall");

        }

        [HttpGet]
        public override ActionResult update(int id)
        {
            var ht = repository.SelectByID<NhaSX>(id);
            var model = new NhaSXModel
            {
                MaNSX = ht.MaNSX,
                TenNSX = ht.TenNSX,
                Email = ht.Email,
                Diachi = ht.DiaChi,
                DienThoai = ht.DienThoai,
                fax = ht.Fax,

            };
            return View(model);
        }
        [HttpPost]
        public override ActionResult update(FormCollection fr)
        {
            var ht = new NhaSXModel
            {
                MaNSX = Convert.ToInt32(fr.Get("mansx")),
                TenNSX = fr.Get("tennsx"),
                Diachi = fr.Get("diachi"),
                Email = fr.Get("email"),
                DienThoai = fr.Get("dienthoai"),
                fax = fr.Get("fax"),
            };
            var model = repository.SelectByID<NhaSX>(ht.MaNSX);
            model.TenNSX = ht.TenNSX;
            model.DienThoai = ht.DienThoai;
            model.DiaChi = ht.Diachi;
            model.Email = ht.Email;
            model.Fax = ht.fax;
            repository.commitchanges();
            return RedirectToAction("getall");
        }
    }
}
